<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>三个并列的留言板</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f0f0f0;
            color: #333;
            display: flex;
            justify-content: center;
            align-items: flex-start;
            flex-wrap: wrap;
        }
        .container {
            width: 30%;
            margin: 10px;
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 5px;
            overflow: hidden;
        }
        .messages {
            padding: 10px;
            height: 300px;
            overflow-y: auto;
            border-bottom: 1px solid #ddd;
        }
        .message {
            margin-bottom: 10px;
            padding: 5px;
            background-color: #f9f9f9;
            border: 1px solid #eee;
            border-radius: 5px;
        }
        .input-container {
            display: flex;
            gap: 10px;
            padding: 10px;
        }
        .input-container input[type="text"] {
            flex: 1;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        .input-container button {
            padding: 10px 20px;
            border: 1px solid #ddd;
            background-color: #fff;
            cursor: pointer;
            border-radius: 5px;
        }
        .input-container button:hover {
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>留言板 1</h2>
        <div class="messages" id="messages1"></div>
        <div class="input-container">
            <input type="text" id="message-input1" placeholder="输入留言">
            <button id="send-message1">发送</button>
        </div>
    </div>
    <div class="container">
        <h2>留言板 2</h2>
        <div class="messages" id="messages2"></div>
        <div class="input-container">
            <input type="text" id="message-input2" placeholder="输入留言">
            <button id="send-message2">发送</button>
        </div>
    </div>
    <div class="container">
        <h2>留言板 3</h2>
        <div class="messages" id="messages3"></div>
        <div class="input-container">
            <input type="text" id="message-input3" placeholder="输入留言">
            <button id="send-message3">发送</button>
        </div>
    </div>

    <script>
        function setupMessageBoard(containerId, inputId, buttonId) {
            const messagesContainer = document.getElementById(containerId);
            const messageInput = document.getElementById(inputId);
            const sendMessageButton = document.getElementById(buttonId);

            sendMessageButton.addEventListener('click', function() {
                const messageText = messageInput.value.trim();
                if (messageText === '') return;

                const newMessage = document.createElement('div');
                newMessage.classList.add('message');
                newMessage.textContent = messageText;

                    messagesContainer.appendChild(newMessage);

                // 清空输入框
                messageInput.value = '';
            });

            // 按下回车键发送留言
            messageInput.addEventListener('keypress', function(event) {
                if (event.key === 'Enter') {
                    sendMessageButton.click();
                }
            });
        }

        // 设置三个留言板
        setupMessageBoard('messages1', 'message-input1', 'send-message1');
        setupMessageBoard('messages2', 'message-input2', 'send-message2');
        setupMessageBoard('messages3', 'message-input3', 'send-message3');
    </script>
</body>
</html>